﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using LCTMoodle.Service;
using LCTMoodle.Models.DataModels;

namespace LCTMoodle.Models.ViewModels
{
    public class KhoaHocViewModel : Model
    { 
        public int ma { get; set; }
        public string tenKhoaHoc { get; set; }
        public int maGiangVien { get; set; }
        public string tenGiangVien { get; set; }
        public string moTa { get; set; }
        public int maChuDe { get; set; }
        public string tenChuDe { get; set; }
        public KhoaHoc_ThanhVienViewModel khoaHoc_ThanhVien { get; set; }

        public override void assignModel(SqlDataReader dr)
        {
            for (int i = 0; i < dr.FieldCount; i++)
            {
                switch (dr.GetName(i))
                {
                    case "Ma":
                        ma = (dr.IsDBNull(i)) ? 0 : dr.GetInt32(i); break;
                    case "TenKhoaHoc":
                        tenKhoaHoc = (dr.IsDBNull(i)) ? null : dr.GetString(i); break;
                    case "MaGiangVien":
                        maGiangVien = (dr.IsDBNull(i)) ? 0 : dr.GetInt32(i); break;
                    case "TenGiangVien":
                        tenGiangVien = (dr.IsDBNull(i)) ? null : dr.GetString(i); break;
                    case "MoTa":
                        moTa = (dr.IsDBNull(i)) ? null : dr.GetString(i); break;
                    case "MaChuDe":
                        maChuDe = (dr.IsDBNull(i)) ? 0 : dr.GetInt32(i); break;
                    case "TenChuDe":
                        tenChuDe = (dr.IsDBNull(i)) ? null : dr.GetString(i); break;
                    case "KhoaHoc_ThanhVien":
                        khoaHoc_ThanhVien = HttpContext.Current.Session["NguoiDung"] == null ? null : KhoaHoc_ThanhVienService.layKhoaHocThanhVienTheoMaKhoaHocVaMaThanhVien(ma, ((NguoiDungViewModel)HttpContext.Current.Session["NguoiDung"]).ma);
                        break;
                    default:
                        break;
                }
            }
        }
    }
}